package pl.enigmatic.random;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;


public class DiscreteRandom<X> extends Random<X> {

	private final List<X> list;

	public DiscreteRandom(final List<X> list) {
		this.list = list;
	}

	public DiscreteRandom() {
		this(new Vector<X>());
	}

	public DiscreteRandom(X[] list) {
		this();
		for (X x : list) {
			this.list.add(x);
		}
	}

	public X getRandomValue() {
		if (isEmpty()) {
			return null;
		} else {
			return list.get(getInteger(0, list.size() - 1));
		}
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public boolean add(final X arg0) {
		return list.add(arg0);
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#addAll(java.util.Collection)
	 */
	public boolean addAll(final Collection<? extends X> arg0) {
		return list.addAll(arg0);
	}

	/**
	 * 
	 * @see java.util.List#clear()
	 */
	public void clear() {
		list.clear();
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#contains(java.lang.Object)
	 */
	public boolean contains(final Object arg0) {
		return list.contains(arg0);
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#get(int)
	 */
	public X get(final int arg0) {
		return list.get(arg0);
	}

	/**
	 * @return
	 * @see java.util.List#isEmpty()
	 */
	public boolean isEmpty() {
		return list.isEmpty();
	}

	/**
	 * @return
	 * @see java.util.List#iterator()
	 */
	public Iterator<X> iterator() {
		return list.iterator();
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#remove(java.lang.Object)
	 */
	public boolean remove(final Object arg0) {
		return list.remove(arg0);
	}

	/**
	 * @param arg0
	 * @return
	 * @see java.util.List#removeAll(java.util.Collection)
	 */
	public boolean removeAll(final Collection<?> arg0) {
		return list.removeAll(arg0);
	}

	/**
	 * @return
	 * @see java.util.List#size()
	 */
	public int size() {
		return list.size();
	}

	/**
	 * @return
	 * @see java.util.List#toArray()
	 */
	public Object[] toArray() {
		return list.toArray();
	}

	/**
	 * @param <T>
	 * @param arg0
	 * @return
	 * @see java.util.List#toArray(T[])
	 */
	public <T> T[] toArray(final T[] arg0) {
		return list.toArray(arg0);
	}
}
